home *** CD-ROM | disk | FTP | other *** search
/ Software USA 4 #1 / Software USA Volume 4.01.iso / mac / Home and Office / DragStrip / Writing DragStrip Additions / SampleAddition.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-03  |  2.4 KB  |  115 lines  |  [TEXT/MMCC]

  1. #include <Palettes.h>
  2. #include <GestaltEqu.h>
  3. #include <Icons.h>
  4. #include <A4Stuff.h>
  5. #include "DS Additions.h"
  6. #include "Drag.h"
  7.  
  8. #define ScreenDepth(gdh) ((*((*gdh)->gdPMap))->pixelSize)
  9.  
  10. pascal long main( DSAdditionParamBlockPtr params)
  11. {
  12.     long         result = 0;
  13.     Rect        localRect;
  14.     Point        mousePoint;
  15.     OSErr        theErr;
  16.     RGBColor    redColor, blueColor;
  17.     long        oldA4 = SetCurrentA4();
  18.     
  19.     switch(params->dsMessage) {
  20.         /////////
  21.         //    Given a draw message, draw what we need into the 
  22.         //    provided rectangle
  23.         /////////
  24.         case kMsgInitAddition:
  25.             params->dsRefCon = (long)NewHandle(10);    //Allocate some memory for some reason
  26.             result = MemError();
  27.             break;
  28.  
  29.         case kMsgCloseAddition:
  30.             if(params->dsRefCon != nil) {
  31.                 DisposeHandle((Handle)params->dsRefCon);
  32.             }
  33.             break;
  34.  
  35.         case kMsgDraw:
  36.             localRect = params->dsTextRect;
  37.             
  38.             redColor.red = 0xffff;
  39.             redColor.green = 0x0000; 
  40.             redColor.blue = 0x0000;
  41.             RGBForeColor(&redColor);
  42.             
  43.             if((localRect.right - localRect.left) >= 20) {
  44.                 TextFont(applFont);
  45.                 TextFace(0);
  46.                 TextSize(9);
  47.                 TextBox("Hello", 5, &localRect , teCenter);
  48.             }
  49.             params->dsNextDrawTime = TickCount() + 300;    //Draw again in 5 seconds
  50.             break;
  51.  
  52.         /////////
  53.         //    Given a draw hilite message, draw what we need into 
  54.         //    the provided rectangle
  55.         /////////
  56.         case kMsgDrawHilite:
  57.             localRect = params->dsTextRect;
  58.             
  59.             blueColor.red = 0x0000;
  60.             blueColor.green = 0x0000; 
  61.             blueColor.blue = 0xffff;
  62.             RGBForeColor(&blueColor);
  63.  
  64.             if((localRect.right - localRect.left) >= 20) {
  65.                 TextFont(applFont);
  66.                 TextFace(0);
  67.                 TextSize(9);
  68.             
  69.                 TextBox("World", 5, &localRect , teCenter);
  70.             }
  71.             break;
  72.  
  73.             
  74.             params->dsNextDrawTime = TickCount() + 300;    //Draw again in 5 seconds
  75.  
  76.         /////////
  77.         //    Given a hit message, do whatever we do when we are hit
  78.         /////////
  79.         case kMsgHit:
  80.             localRect = params->dsLocalRect;
  81.             GetMouse(&mousePoint);
  82.  
  83.             //Make sure that the user actually let go inside the rect
  84.             //before doing our thing.
  85.             while(StillDown() && PtInRect(mousePoint, &localRect)) {
  86.                 GetMouse(&mousePoint);
  87.             }
  88.  
  89.             if(!StillDown()) {
  90.                 SysBeep(10);
  91.             }
  92.             break;
  93.  
  94.         /////////
  95.         //    Given a drop message, pull the files out of the 
  96.         //    DragReference then do what you want with them.
  97.         /////////
  98.         case kMsgDropOccurred:
  99.             {
  100.                 unsigned short    items, index;
  101.  
  102.                 CountDragItems(params->dsDragReference, &items);
  103.                     for (index = 1; index <= items; index++) {
  104.                     SysBeep(10);
  105.                 }
  106.             }
  107.             break;
  108.  
  109.  
  110.     }
  111.     
  112.     SetA4(oldA4);
  113.     return result;
  114. }
  115.